package com.ruoyi.project.outpatient.service.impl;

import com.ruoyi.project.hissystem.domain.HisDepartment;
import com.ruoyi.project.hissystem.mapper.HisDepartmentMapper;
import com.ruoyi.project.hissystem.mapper.HisRegistraFeeMapper;
import com.ruoyi.project.outpatient.domain.Register;
import com.ruoyi.project.outpatient.mapper.CaseMapper;
import com.ruoyi.project.outpatient.mapper.NewVisitMapper;
import com.ruoyi.project.outpatient.mapper.OutPatientMapper;
import com.ruoyi.project.outpatient.service.NewVisitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class NewVisitServiceImpl implements NewVisitService {
    @Autowired
    private NewVisitMapper newVisitMapper;
    @Autowired
    private OutPatientMapper outPatientMapper;
    @Autowired
    private CaseMapper caseMapper;
    @Autowired
    private HisDepartmentMapper hisDepartmentMapper;
    @Autowired
    private HisRegistraFeeMapper hisRegistraFeeMapper;

    @Override
    public List<Register> selectByStatus(Character status) {
        List<Register> list = this.newVisitMapper.selectByStatus(status);
        for (Register r:list) {
            //查询患者
            System.out.println("==="+r+"-_-");
            r.setOutPatient(this.outPatientMapper.selectPatientById(r.getOutPatient().getPatientId()));
            //查询病例
            if(r.getACase()!=null){
                r.setACase(this.caseMapper.selectById(r.getACase().getCaseId()));
            }
            //查询部门
            r.setHisDepartment(this.hisDepartmentMapper.selectDepartmentById(r.getHisDepartment().getDepartId()));
            //查询挂号类型
            r.setRegistraFee(this.hisRegistraFeeMapper.selectRegistraFeeById(r.getRegistraFee().getRegistraFeeId()));
            System.out.println("-_-"+r+"-_-");
        }
        return list;
    }

    @Override
    @Transactional
    public void modifyIsStatus(Integer id, Character status) {
        this.newVisitMapper.updateIsStatus(id,status);
    }
}
